<?php

namespace App\Http\Controllers\Api\Train;

use App\Http\Controllers\Controller;
use App\Http\Resources\Train\Issue\IssueResource;
use App\Models\Train\TrainIssues\TrainIssue;
use Illuminate\Http\Request;


class IssueController extends Controller
{
    public function issues(Request $request)
    {
        $order_state = $request->input('order_state', 0) ?: 0;
        $order_sn    = $request->input('order_sn', '') ?: '';
        return $this->success('success', [
            'issues' => IssueResource::collection((new TrainIssue())->listIssue($order_state, $order_sn)),
        ]);
    }

    public function issue(Request $request)
    {
        $data = $request->all();
        (new TrainIssue())->addIssue($data);
        return $this->success('success');
    }
}
